<?php
	session_start();
	
	header('content-type:image/jpeg');
	$img = imagecreatetruecolor(150,50);
	$bgcolor = imagecolorallocate($img,rand(0,125),rand(0,125),rand(0,125));
	imagefill($img,0,0,$bgcolor);
	
	//背景上画画写字
	for($i = 1;$i < 500;$i++){
		$pixX = rand(5,145);
		$pixY = rand(5,45);
		$pixColor = imagecolorallocate($img,rand(126,255),rand(126,255),rand(126,255));
		
		imagesetpixel($img,$pixX,$pixY,$pixColor);
	}
	
	//简历一个空字符串变量
	$vCode = '';
	
	$zimu = '1234567890qwertyuiopasdfghjklzxcvbnm';
	for($j = 1;$j <= 4;$j++){
		$fontSize = rand(15,25);
		$fontX =(100/4)*$j;
		$fontY = 30;
		$fontColor = imagecolorallocate($img,rand(126,255),rand(126,255),rand(126,255));
		$fontText = $zimu[rand(0,strlen($zimu) - 1)];
		
		//把循环的字符串 连接在一起
		$vCode .=$fontText;
		
		imagettftext($img,$fontSize,0,$fontX,$fontY,$fontColor,'./simkai.ttf',$fontText);
	}
	
	$_SESSION['vcode'] = $vCode;
	

	
	//输出或保存
	imagejpeg($img);
	//关闭画布
	imagedestroy($img);
?>